package com.example.ch3_1event;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //获取控件对象
        getViews();
        //注册监听器
        setListener();



    }

    private void setListener() {
        //实例化监听器对象
        CustomClickListener listener = new CustomClickListener();
        btn.setOnClickListener(listener);


    }

    private void getViews() {
        btn = findViewById(R.id.btn);

    }

    //自定义点击事件监听器
    class CustomClickListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Log.i("msg","按钮点击");
        }
    }


}